<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
${aier_doctype}
<html <s:property value="aier-html-xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="${aier_content_type}" />
<meta name="keywords" content="${aier_keyworks}" />
<meta name="description" content="${aier_description}" />
<title>${aier_title}</title>
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}ui.css" />
<link rel="stylesheet" href="${aier_css_url}jc/chosen.css">
<link rel="Stylesheet" href="${aier_css_url}jq/jq.css" />
<link rel="Stylesheet" href="${aier_css_url}jq/multiselect.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/jq-msg.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/reset.css" />
<link rel="stylesheet" href="${aier_css_url}social/school/smanage.css" />

<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/hh/ui.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}97/WdatePicker.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/block.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/multiselect.js"></script>
<script type="text/javascript" src="${aier_js_url}jc/cj.js"></script>
<script type="text/javascript"
	src="${aier_js_url}social/school/attend/smdut.js"></script>
<script type="text/javascript">
	var global_suffix = "${aier_suffix}", global_url = "${aier_url}", global_uri = "${aier_uri}", global_urijs = "${aier_urijs}", 
		global_sid = "${sid}", global_tid = "${tid}";
</script>
</head>
<!-- 值班管理 -->
<body>


	<!-- 顶栏 -->
	<s:action name="userhomecomm_homeHead" namespace="/user"
		executeResult="true"></s:action>

	<!-- 正文 -->
	<div id="hfContent" class="ar-content">
		<div class="content-main">
			<!-- 学校名称栏 -->
			<s:action name="scomm_schoolMTitle" namespace="/school"
				executeResult="true"></s:action>
			<div class="main-content wrap-bg clearfix">
				<!-- 左侧栏 -->
				<s:action name="scomm_schoolMLeft" namespace="/school"
					executeResult="true"></s:action>
				<!-- 右侧内容 -->
				<div class="ae-right">
					<div class="right-main">
						<div class="right-main-top">
							<div class="binfo-title">
								<h3>值班管理</h3>
							</div>
							<div class="right-line"></div>
						</div>
						<div class="right-main-c">
							<div class="info-tab01">
								<table id="inviteParTable">
									<tbody>
										<tr>
											<th class="gray6">起始时间：</th>
											<td><input type="text" id="txt_dmst" class="PY-input"
												onfocus="WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:true})" />
											</td>
											<th class="gray6">结束时间：</th>
											<td><input type="text" id="txt_dmet" class="PY-input"
												onfocus="WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:true})" />
											</td>

										</tr>

										<tr>
											<th class="gray6">教师姓名与账户：</th>
											<td><s:select id="selTname" list="tnameAccountList"
													data-placeholder="请选择或输入姓名与账号" cssClass="chosen"
													tabindex="4">
												</s:select></td>
											<th class="gray6">职务:</th>
											<td><select id="selTgrade" data-placeholder="请选择或输入职务"
												class="chosen" tabindex="1">
													<option value="-1">所有职务</option>
													<c:forEach var="sg" items="${schoolGradeList }">
														<option value="${sg.gid}">${sg.name}</option>
													</c:forEach>
											</select></td>
											<td style="width:150px;" align="right"><a id="b_hmsel"
												onclick="search_duy()" href="javascript:;"
												class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only fr"
												role="button" aria-disabled="false"><span
													class="ui-button-text">查询</span> </a></td>
										</tr>

										<tr>
											<td colspan="5" align="right"><a id="b_dmadd"
												href="javascript:;"
												class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only fr"
												role="button" aria-disabled="false"><span
													class="ui-button-text">添加</span> </a></td>
										</tr>
									</tbody>

								</table>
							</div>

						</div>
						<div class="right-main-down">
							<div class="down-line"></div>

							<div class="down-inre">
								<table id="dutyinfo"></table>
								<div id="dutypage"></div>
							</div>
						</div>
					</div>
				</div>
			</div>

		</div>
		<!-- footer copyright -->
		<s:action name="userhomecomm_homeFooter" namespace="/user"
			executeResult="true"></s:action>
		<!-- /footer copyright -->
	</div>



	<!-- 弹出层内容 -->
	<div id="d_dmaddDuty" title="添加值班" style="display: none;">
		<div class="info-tab01">
			<table>
				<tbody>
					<tr>
						<td colspan="4"><div>请设置值班教师或指定值班职务</div></td>
					</tr>
					<tr>
						<th class="gray6">职务：</th>
						<td><select id="selTgrade_add" data-placeholder="请选择或输入职务"
							onchange="changetypeexc()" class="chosen" tabindex="1">
								<option value="-1">请选择</option>
								<c:forEach var="sg" items="${schoolGradeList }">
									<option value="${sg.gid}">${sg.name}</option>
								</c:forEach>
						</select></td>
						<th class="gray6">教师姓名与账号：</th>
						<td><div class="sel_position" id="sel_position_teacher_exc">
								<s:select id="selTname_add" list="tnameAccountList"
									data-placeholder="请选择或输入姓名与账号" cssClass="chosen" tabindex="4">
								</s:select>
							</div></td>

					</tr>
					<tr>
						<th class="gray6">开始时间：</th>
						<td><input id="txt_dmsdate" type="text" class="PY-input"
							onfocus="WdatePicker({skin:'twoer',startDate:'%y-%M-%d %H:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:true})">
						</td>
						<th class="gray6">结束时间：</th>
						<td><input id="txt_dmedate" type="text" class="PY-input"
							onfocus="WdatePicker({skin:'twoer',startDate:'%y-%M-%d %H:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:true})">
						</td>

					</tr>

				</tbody>
			</table>
		</div>
	</div>


	<!-- 提示弹出层 -->
	<div id="duty_del" style="display: none;" title="撤销值班">
		您确定要将<span id="deltname"></span> 的这条值班撤销吗?
	</div>

	<!-- 提示弹出层 -->
	<div id="duty_add" style="display: none;" title="提示">
		确定要给该职务的所有老师添加值班信息吗？</div>
</body>
<script type="text/javascript">
$(".chosen").chosen();
 
	$(function() {
		var txt_dmsdate = $('#txt_dmsdate'),
		txt_dmedate = $('#txt_dmedate'),
		allFields = $( [] ).add(txt_dmsdate).add(txt_dmedate);
		//添加值班弹出层
		$("#d_dmaddDuty").dialog({
			//背景变暗
			modal: true,
			autoOpen : false,
			show : "fade",
	        hide : "fade",
			width : "670",
			height : "410",
			buttons: {
				"确定": function() {
					addTel();
					
				},"取消": function() {
					$( this ).dialog( "close" );
				}
			},
		close: function() {
			allFields.val( "" ).removeClass( "ui-state-error" );
		}
		});
		$("#b_dmadd").click(function() {
			$("#d_dmaddDuty").dialog("open");
			return false;
		});
		
		
	});
	
	
	
	function search_duy(){
		var sid = "${sid }";
		var nameAndAccount = $("#selTname").val();
		if(nameAndAccount=="请选择"){
			var taccount = "";	
		}else{
			var taccount = nameAndAccount.split(" ")[1];
		}
		var typeId = $('#selTgrade  option:selected').val();
		var txt_sdate = $('#txt_dmst').val();
		var txt_edate = $('#txt_dmet').val();
		jQuery("#dutyinfo").jqGrid('setGridParam',{url:"${aier_url}${aier_urijs}schooldut_search${aier_suffix}?sid="+sid+"&account="+taccount
			+"&gid="+typeId+"&txt_sdate="+txt_sdate+"&txt_edate="+txt_edate,page:1}).trigger("reloadGrid");
	}

	function addTel(){
		var sid = "${sid }";
		var nameAndAccount = $("#selTname_add").val();
		if(nameAndAccount=="请选择"){
			var taccount_add = "";	
		}else{
			var taccount_add = nameAndAccount.split(" ")[1];
		}
		var typeId_add = $('#selTgrade_add  option:selected').val();
		var txt_sdate_add = $('#txt_dmsdate').val();
		var txt_edate_add = $('#txt_dmedate').val();		
		if(txt_sdate_add.trim()==""){
			$().message("请输入值班开始时间");
			return
		}
		if(txt_edate_add.trim()==""){
			$().message("请输入值班结束时间");
			return
		}
		if(txt_edate_add<txt_sdate_add){
			$().message("结束时间必须大于等于开始时间");
			return
		}
		if(typeId_add==-1&&taccount_add==""){
			$().message("请选择一个职务或教师");
			return
		}
		if(typeId_add!=-1 && taccount_add==""){
			$(function() {
				$( "#duty_add" ).dialog({
					modal: true,
					resizable: false,
					buttons: {
						"确定": function() {
							var fun = function(data) {
								if(1==data.s){
									$().message("添加成功,您可以继续添加!");
									$("#dutyinfo").trigger("reloadGrid");
									$("#d_dmaddDuty").dialog( "close" );
								}else{
									$().message("添加失败,请稍后再试!");
								}
							};
							exeAjax(ajaxUrl("${aier_url}${aier_urijs}schooldut_add${aier_suffix}"), fun, 
								{"sid" : sid,"account" :taccount_add,"gid" :typeId_add,
								 "txt_sdate":txt_sdate_add,"txt_edate":txt_edate_add});
							$( this ).dialog( "close" );
							},"取消": function() {
							$( this ).dialog( "close" );
						}
					}
				});
			});
		}else{
			var fun = function(data) {
				if(1==data.s){
					$().message("添加成功,您可以继续添加!");
					$("#dutyinfo").trigger("reloadGrid");
					$("#d_dmaddDuty").dialog( "close" );
				}else{
					$().message("添加失败,请稍后再试!");
				}
			};
			exeAjax(ajaxUrl("${aier_url}${aier_urijs}schooldut_add${aier_suffix}"), fun, 
				{"sid" : sid,"account" :taccount_add,"gid" :typeId_add,
				 "txt_sdate":txt_sdate_add,"txt_edate":txt_edate_add});
		}
		
					
	}

	//改变职务(异常处理) 
	function changetypeexc(){
		var typeId_add = $('#selTgrade_add option:selected').val();
		var fun = function(data) { 
			var t = "<select id='selTname_add' Class='chosen' tabindex='1' ><option value='请选择'>请选择</option>";
			if(data.tnameAccountList!=null&&data.tnameAccountList.length>0){
				for ( var i = 0; i < data.tnameAccountList.length; i++) {
					var tnameAccount = data.tnameAccountList[i];
					t += "<option value='"+tnameAccount+"'>" + tnameAccount + "</option>";
				}
			};
			t += "</select>";
			$('#sel_position_teacher_exc').html(t);
			$(".chosen").chosen();
		};
		exeAjax(ajaxUrl("${aier_url}${aier_urijs}schooldut_changetype${aier_suffix}"), fun, 
			{"sid" : global_sid,"gid" :typeId_add});
	}
</script>
</html>